<template>
  <div id="app">
    <div class="alert">
      <p>请使用移动端打开！</p>
    </div>
    <div class="main">
      <ZHeader />
      <router-view/>
    </div>
    <div class="message" v-if="isMessage">
      <p v-if="isSuccess" class="success">{{ message }}</p>
      <p v-else class="error">{{ message }}</p>
    </div>
  </div>
</template>

<script lang="ts" setup>

  import { ref, provide, nextTick } from 'vue';
  import ZHeader from './components/ZHeader.vue';

  const title = ref('成语接龙');
  const showLeft = ref(false);
  const isMessage = ref(false)
  const message = ref('')
  const isSuccess = ref(true)
  provide('nav', {
    title,
    setTitle(val: string) {
      title.value = val;
    },
    showLeft,
    setShowLeft(val: boolean) {
      showLeft.value = val;
    },
    message,
    isMessage,
    isSuccess,
    setIsMessage(text: string, is: boolean) {
      isMessage.value = true;
      message.value = text;
      isSuccess.value = is;
      setTimeout(() => {
        isMessage.value = false;
      }, 2000)
    }
  })
</script>

<style lang="less">
html, body, p, ul, li {
  margin: 0;
  padding: 0;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}

.alert {
  display: none;
}

.main {
  height: 100vh;
  box-sizing: border-box;
}

@keyframes move {
    from {
      top: -60px;
    } to {
      top: 0;
    }
}

.message {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  animation: move .3s linear;

  p {
    width: 100%;
    height: 100%;
    line-height: 60px;
    color: #fff;
    font-size: 16px;
  }
  .success {
    background-color: #42b983;
  }
 .error {
    background-color: #f56c6c;
  }
}

@media screen and (min-width: 900px) {
  .alert {
    display: block;
  }

  .main {
    display: none;
  }
}
</style>
